<template>
	<!-- 我的代金券 -->
	<view class="">
		<view class="header">
			<view @click="currentChange(1)" class="header-item" :class="current==1?'header-item-active':''">
				已使用
			</view>
			<view @click="currentChange(0)" class="header-item" :class="current==0?'header-item-active':''">
				待使用
			</view>
		</view>
		<view class="list" v-if="list.length>0">
			<!-- <view class="list-item" v-for="(item,index) in list" :key="index" v-if="current == 1"> -->
			<view class="list-item" v-for="(item,index) in list" :key="index" @click="gotoMach(item.mch_id)">
				<view class="list-item-left">
					<view class="lil-name">店铺：{{item.merchant.shop_name||'未知'}}</view>
					<view class="lil-good">商品：{{item.goods.name || '未知'}}</view>
					<view class="lil-time">过期时间：{{item.expire_time == '0000-00-00 00:00:00' ? '已过期' : item.expire_time}}
					</view>
					<view class="lil-time">使用时间：{{item.use_time}}
					</view>
				</view>
				<view class="list-item-right">
					<!-- <view class="lir-price" v-if="true">
						{{item.amount}}<text>元</text>
					</view> -->
					<view class="lir-price" v-if="item.is_use == 1">
						已使用
					</view>
					<view class="lir-old" v-if="item.is_use == 0">
						待使用
					</view>
				</view>
			</view>
		</view>
		<view class="isNull" v-if="list.length==0">
			<image src="@/static/nodata.png" mode=""></image>
			<text>暂时没有数据~</text>
		</view>
	</view>
</template>

<script>
	import {
		getBVoucherListApi
	} from "@/common/api.js"
	export default {
		data() {
			return {
				current: 1,
				list: []
			}
		},
		onLoad() {
			this.getBVoucherList()
		},
		methods: {
			gotoMach(mch_id){
				this.$api.get_merchants({},mch_id,1).then(res=>{
					console.log(res,'1233123123');
					let shop = JSON.stringify(res.data)
					uni.navigateTo({
						url:'/pageB/shop?e=' + shop
					})
				})
				
			},
			// 获取现金券列表
			getBVoucherList() {
				getBVoucherListApi({
					is_use: this.current
				}).then(res => {
					this.list = res.data
				})
			},
			currentChange(e) {
				this.current = e
				this.getBVoucherList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.header {
		width: 100%;
		background: #fff;
		display: flex;
		align-items: center;
		border: 1rpx solid #3c9cff;
		box-sizing: border-box;
	}

	.header-item {
		flex: 1;
		text-align: center;
		padding: 14rpx 0;
		font-size: 32rpx;
	}

	.header-item-active {
		background: #3c9cff;
		color: #fff;
	}

	.list {
		padding: 0 30rpx;

	}

	.list-item {
		padding: 30rpx;
		background: #fff;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-radius: 10rpx;
		margin-top: 20rpx;
	}

	.lir-price {
		font-size: 32rpx;
		color: red;

		text {
			font-size: 28rpx;
		}
	}

	.lir-old {
		font-size: 32rpx;
		color: #999;
	}

	.lil-name {
		font-size: 32rpx;
	}

	.lil-good {
		font-size: 28rpx;
		margin: 10rpx 0;
	}

	.lil-time {
		font-size: 24rpx;
		color: #999;
	}

	.isNull {
		margin-top: 200rpx;
		display: flex;
		flex-direction: column;
		align-items: center;

		image {
			width: 410rpx;
			height: 240rpx;
			flex-shrink: 0;
		}

		text {
			margin-top: 30rpx;
			font-size: 28rpx;
			color: #999;
		}
	}
</style>